home *** CD-ROM | disk | FTP | other *** search
/ Family Forum 261 / SOMC Family Forum 261.iso / Xtras / Behavior Library.cst / 00029_Script_Net Get Text < prev    next >
Text File  |  1997-11-17  |  5KB  |  131 lines

  1. -- Net     Get Text from URL
  2.  
  3.  
  4.  
  5. -- behavior library version 1.1
  6.  
  7. -- This behavior can be used to as a general purpose getNetText script.
  8. -- The behavior is assigned to either a button or a frame Script.  
  9.  
  10. -- The required properties are:
  11. -- "On Which Event" - this is either MouseUp or ExitFrame.
  12. -- "URL" - this is an http path
  13. -- "Channel number of field"  -  this is the field that will receive the text.
  14. -- Use the Score channel number of the field.
  15. -- "Timeout seconds" - this is the amount of time in seconds that will pass 
  16. -- before the getNetText call is aborted.
  17.  
  18. -- IMPORTANT NOTE FOR USE IN A FRAME SCRIPT
  19. -- After this script is finished, the play head will progress 
  20. -- to the next frame.  Therefore, you will probably want to follow the 
  21. -- frame that contains this script with a frame that contains the pResult 
  22. -- field and a "go to the frame" script in the script channel.
  23. -- there are other options available.  Use your imagination.
  24.  
  25. -- You may use the URL http://www.cedub.com/bin/fortune.cgi as an example.
  26. -- This cgi script returns a line of text.
  27.  
  28. property pNetID         -- set to getLatestNetID()
  29. property pResult        -- the spriteNum of field that receives netTextResult()
  30. property pStartAction   -- if true, net operation is taking place
  31. property pExitFrameDone -- if true exitFrame operation if finished
  32. property pWhichEvent    -- how the event is activated.  mouseUp or exitFrame.
  33. property pURL           -- which URL is called
  34. property pTicks         -- number of ticks before the operation times out.
  35. property pEndTicks      -- pTicks * 60.
  36.  
  37. on mouseUp  
  38.   
  39.   if pStartAction = FALSE then    
  40.     set pNetID = getNetText(pURL) -- this sets the netID and calls getNetText 
  41.     cursor 4
  42.     set pStartAction = TRUE
  43.     -- the following sets up the timeout variable
  44.     set pEndTicks = pTicks
  45.     set pEndTicks = pEndTicks * 60  
  46.     set pEndTicks = the ticks + pEndTicks
  47.   end if 
  48. end
  49.  
  50. on prepareFrame me
  51.   
  52.   if pWhichEvent = #mouseUp then
  53.     finishOperation
  54.   end if
  55. end
  56.  
  57. on exitFrame me
  58.   
  59.   if (pWhichEvent = #exitFrame) and (NOT pExitFrameDone = TRUE) then    
  60.     put pExitFrameDone
  61.     
  62.     if NOT pStartAction = TRUE then
  63.       -- do the same work as on mouseUp
  64.       set pNetID = getNetText(pURL)
  65.       cursor 4
  66.       set pStartAction = TRUE
  67.       set pEndTicks = pTicks
  68.       set pEndTicks = pEndTicks * 60  
  69.       set pEndTicks = the ticks + pEndTicks
  70.     end if
  71.     
  72.     if pStartAction = TRUE then
  73.       finishOperation
  74.       go to the frame
  75.       
  76.     end if
  77.   end if
  78. end
  79.  
  80. on finishOperation me
  81.   
  82.   if  (pStartAction = TRUE) and (the ticks > pEndTicks) then  -- timeout has passed  
  83.     netAbort(pNetID)  -- abort the operation
  84.     set outputMember = the member of sprite pResult  -- outputMember is a member ref
  85.     set the text of outputMember = "Timeout!"
  86.     set pStartAction = FALSE
  87.     set pExitFrameDone = TRUE
  88.     cursor 0
  89.     
  90.   else if (pStartAction = TRUE) and (netDone(pNetID) = 1) then
  91.     
  92.     if NOT (netError(pNetID) = "") then  -- netError has returned something
  93.       
  94.       if (netError() = "OK") or (netError() =  "none") then  -- complete the operation
  95.         set outputMember = the member of sprite pResult  
  96.         set the text of outputMember = netTextResult(pNetID)
  97.         set pStartAction = FALSE
  98.         set pExitFrameDone = TRUE
  99.         cursor 0
  100.         
  101.       else  -- operation failed
  102.         set outputMember = the member of sprite pResult
  103.         set the text of outputMember = netError()
  104.         set pStartAction = FALSE 
  105.         set pExitFrameDone = TRUE
  106.         cursor 0
  107.         
  108.       end if
  109.     end if  
  110.   end if
  111. end
  112.  
  113. ---
  114.  
  115. on beginSprite me
  116.   set pStartAction = FALSE  -- no action taking place yet   
  117. end
  118.  
  119. on getPropertyDescriptionList
  120.   
  121.   set p_list = [           #pURL: [ #comment:   "Source URL:",                     #format:   #string,                    #default:   "http://www.cedub.com/bin/fortune.cgi" ],        #pResult: [ #comment:   "Target Sprite:",                     #format:   #integer,                    #default:    1 ],     #pWhichEvent: [ #comment:   "Initializing Event:",                     #format:   #symbol,                      #range: [ #MouseUp, #ExitFrame ],                    #default:   #MouseUp ],         #pTicks: [ #comment:   "Network Timeout:",                     #format:   #integer,                    #default:    40 ]                  ]
  122.   return p_list  
  123.  
  124. end
  125.  
  126. on getBehaviorDescription
  127.   return "Loads text retrieved from the designated URL into a field castmember. Attach to sprites or frames." & RETURN & "PARAMETERS:" & RETURN & "ò Source URL - Enter the full URL of the desired text."  & RETURN & "ò Target Sprite - Enter the channel number of a sprite with a field cast member in the current frame. The field cast member will hold the retrieved text."  & RETURN & "ò Initializing Event - Specify the event that will trigger the behavior."  & RETURN & "ò Network Timeout - Enter the number of seconds to wait before canceling operation due to no response from remote server."
  128.  
  129. end
  130.  
  131. -- 1/20/97 Chris Walcott